import tim from "../../tim";
import Vue from "vue";
const pageIndex = {
  state: {
    active: "top",
    activeBnnerIndex: -1,
    pageObj: {
      title: "", //网页标题
      piclink: "", //缩略图
      introduction: "", //网页简介
      logo: "", //网页logo
      background: "", //背景图
      tuanzhang: "", //是否显示自提点定位
      module: [],
      banner: []
    },
    iconObj: {
      //首页左右图标
      types: "headIcon",
      banner: [
        {
          title: "",
          links: "",
          text: "头部菜单左分类",
          show: "1",
          piclink: "send-gift-o"
        },
        {
          title: "",
          links: "",
          text: "头部菜单右分类",
          show: "1",
          piclink: "send-gift-o"
        }
      ]
    },
    bannerList: {
      //首页轮播图
      show: "1",
      types: "slide",
      banner: []
    },
    menuList: {
      //首页金刚导航
      style: "5",
      types: "navigation",
      show: "1",
      banner: []
    },
    seckill: {
      show: "1",
      title: "限时秒杀",
      title_en: "超值特惠",
      types: "seckill",
      banner: []
    },
    presale: {
      show: "1",
      title: "精品预售",
      title_en: "好产品提前订",
      types: "presale",
      banner: []
    },
    collage: {
      show: "1",
      title: "拼团购物",
      title_en: "好产品提前订",
      types: "collage",
      banner: []
    },
    merchant: {
      show: "1",
      title: "商户类别",
      title_en: "好产品提前订",
      types: "merchant",
      banner: []
    },
    course: {
      show: "1",
      title: "内容付费",
      title_en: "好产品提前订",
      types: "course",
      banner: []
    },
    shop: {
      show: "1",
      title: "null",
      title_en: "",
      style: "0",
      types: "shop",
      banner: []
    },
    news: {
      show: "1",
      title: "实时资讯",
      title_en: "",
      style: "0",
      types: "news",
      text: "",
      banner: []
    },
    shopsModule: {
      show: "1",
      title: "",
      title_en: "",
      style: "0",
      types: "modules",
      text: "",
      banner: [
        {
          banner: [],
          desc: "",
          show: "1",
          sort: "3",
          style: "1",
          title: "服饰分类"
        }
      ]
    },
    partListCon: [
      {
        banner: [],
        desc: "",
        show: "1",
        sort: "3",
        style: "1",
        title: "服饰分类",
        title_en: "精选分类由你挑",
        types: "modules"
      }
    ],
    footer: {
      show: "1",
      title: "",
      title_en: "",
      style: "0",
      types: "footer",
      text: "",
      banner: [{ piclink: "home-o", links: "", title: "首页", id: 0, sort: "" }]
    },
    delBanner: "",
    delMudeules: "",
    modules: [],
    showModuleRight: {
      types: "",
      style: "0",
      title: "",
      link: "",
      text: "",
      sort: "",
      show: "1",
      banner: []
    },
    activeModuleIndex: -1
  },
  mutations: {
    setSeckillShops(state, arr) {
      state.modules[state.activeModuleIndex].banner = arr;
    },
    addModulesBannerItemShop(state, obj) {
      state.modules[state.activeModuleIndex].banner.push(obj);
    },
    editModules(state, obj) {
      state.modules[state.activeModuleIndex][obj.key] = obj.value;
    },
    hideModules(state) {
      console.log(state.activeModuleIndex);
      state.modules.splice(state.activeModuleIndex, 1);
      // state.active = "top";
    },
    toShowModuleRight(state, objs) {
      state.showModuleRight = objs.obj;
      state.activeModuleIndex = objs.i;
    },
    addNewModules(state, obj) {
      var objs = {
        types: obj.types,
        style: "0",
        title: obj.title,
        link: "",
        text: "",
        sort: "",
        show: "1",
        banner: []
      };
      console.log(state.modules);
      state.modules.push(objs);
      state.active = obj.i;
      // state.active = obj.types + "-" + obj.i;
    },
    delAdvertisement(state, id) {
      if (id) {
        state.delMudeules += id + "@";
      }
      state.partListCon.splice(state.activeBnnerIndex, 1);
      state.activeBnnerIndex = -1;
      state.active = "top";
    },
    showModeules(state, type) {
      if (type == "slides") {
        state.active = "slides";
        state.bannerList.show = "1";
      } else if (type == "menu") {
        state.active = "menu";
        state.menuList.show = "1";
      } else {
        state.active = type;
        state[type].show = "1";
      }
    },

    setPageObj(state, pageObj) {
      var module = pageObj.module;
      var arr = [];
      for (var i in module) {
        if (module[i].types == "headIcon") {
          state.iconObj = module[i];
        } else if (module[i].types == "footer") {
          state.footer = module[i];
        } else {
          arr.push(module[i]);
        }
      }
      state.modules = arr;
      state.pageObj = pageObj;
    },

    delBannerItem(state, obj) {
      if (obj.type == "slides") {
        state.delBanner += state.bannerList.banner[obj.i].id + "@";
        state.bannerList.banner.splice(obj.i, 1);
      } else if (obj.type == "menu") {
        state.delBanner += state.menuList.banner[obj.i].id + "@";
        state.menuList.banner.splice(obj.i, 1);
      } else {
        state.delBanner += state[obj.type].banner[obj.i].id + "@";
        state[obj.type].banner.splice(obj.i, 1);
      }
    },
    seFooterItem(state, obj) {
      state.footer.banner[obj.index][obj.key] = obj.value;
    },
    addFooter(state) {
      state.footer.banner.push({
        piclink: "",
        links: "",
        title: "",
        id: 0,
        sort: ""
      });
    },
    addAdvertisementArr(state) {
      state.partListCon.push({
        banner: [],
        desc: "",
        show: "1",
        sort: "3",
        style: "0",
        title: "广告标题",
        types: "modules"
      });
    },
    toCheckArrIndex(state, obj) {
      if (obj.i != 0 && obj.type == "up") {
        state.partListCon[state.activeBnnerIndex].banner[
          obj.i
        ] = state.partListCon[state.activeBnnerIndex].banner.splice(
          obj.i - 1,
          1,
          state.partListCon[state.activeBnnerIndex].banner[obj.i]
        )[0];
      }
      if (
        obj.i != state.partListCon[state.activeBnnerIndex].banner.length - 1 &&
        obj.type == "down"
      ) {
        state.partListCon[state.activeBnnerIndex].banner[
          obj.i
        ] = state.partListCon[state.activeBnnerIndex].banner.splice(
          obj.i + 1,
          1,
          state.partListCon[state.activeBnnerIndex].banner[obj.i]
        )[0];
      }
    },
    delAdvertisementIyem(state, i) {
      if (state.partListCon[state.activeBnnerIndex].banner[i].id) {
        state.delBanner +=
          state.partListCon[state.activeBnnerIndex].banner[i].id + "@";
      }
      state.partListCon[state.activeBnnerIndex].banner.splice(i, 1);
    },
    setPartListConBannerItem(state, obj) {
      console.log(obj);
      state.partListCon[state.activeBnnerIndex].banner[obj.index][obj.key] =
        obj.value;
    },
    onChangeBannerPic(state, obj) {
      state.partListCon[state.activeBnnerIndex].banner[obj.i].piclink = obj.pic;
    },
    addAdvertisement(state) {
      state.partListCon[state.activeBnnerIndex].banner =
        state.partListCon[state.activeBnnerIndex].banner || [];
      state.partListCon[state.activeBnnerIndex].banner.push({
        piclink: "",
        links: "",
        sort: "",
        title: "",
        desc: "",
        id: ""
      });
    },
    onChangeBanner(state, obj) {
      state.partListCon[state.activeBnnerIndex][obj.key] = obj.value;
    },
    setNewsItem(state, obj) {
      state.news.text = obj.id;
      state.news.banner = obj.arr;
    },
    seNewsItem(state, obj) {
      state.news[obj.key] = obj.value;
    },
    addShop(state, obj) {
      var str = obj.types;
      switch (str) {
        case "seckill":
          state.seckill.banner.push(obj.value);
          break;
        case "presale":
          state.presale.banner.push(obj.value);
          break;
        case "collage":
          state.collage.banner.push(obj.value);
          break;
        case "merchant":
          state.merchant.banner.push(obj.value);
          break;
        case "course":
          state.course.banner.push(obj.value);
          break;
        case "shop":
          state.shop.banner.push(obj.value);
          break;
        default:
          break;
      }
    },
    onChangeShopType(state, obj) {
      var str = obj.types;
      switch (str) {
        case "seckill":
          state.seckill[obj.key] = obj.value;
          break;
        case "presale":
          state.presale[obj.key] = obj.value;
          break;
        case "collage":
          state.collage[obj.key] = obj.value;
          break;
        case "merchant":
          state.merchant[obj.key] = obj.value;
          break;
        case "course":
          state.course[obj.key] = obj.value;
          break;
        case "shop":
          state.shop[obj.key] = obj.value;
          break;
        default:
          break;
      }
      console.log(state.seckill);
    },
    onChangeStyle(state, obj) {
      var str = obj.types;
      switch (str) {
        case "navigation":
          state.menuList.style = obj.value;
          break;
        default:
          break;
      }
    },
    setChangeShow(state, obj) {
      var str = obj.types;
      switch (str) {
        case "navigation":
          console.log(obj);
          state.menuList.show = obj.value;
          break;
        case "slides":
          state.bannerList.show = obj.value;
          break;
        case "news":
          state.news.show = obj.value;
          break;
        default:
          break;
      }
    },
    seMenuItem(state, obj) {
      console.log(state.menuList.banner[obj.index], obj);
      state.menuList.banner[obj.index][obj.key] = obj.value;
    },
    addMenu(state) {
      state.menuList.banner.push({
        piclink: require("../../assets/img/config/icon01.png"),
        links: "",
        sort: "",
        desc: "",
        introduction: "",
        title: "菜单名",
        id: ""
      });
    },
    setBannerItem(state, obj) {
      state.bannerList.banner[obj.index][obj.key] = obj.value;
    },
    // addBanner(state) {
    //   state.bannerList.banner.push({
    //     piclink: '',
    //     links: '',
    //     title: '',
    //     id: 0,
    //     desc: '',
    //     sort: ''
    //   })
    // },
    updateInput(state, obj) {
      if (obj.type == "headTitle") {
        //修改网站标题
        state.pageObj.title = obj.value;
      } else if (obj.type == "introduction") {
        //修改简介
        state.pageObj.introduction = obj.value;
      } else if (obj.type == "tuanzhang") {
        //修改是否显示自提点定位
        state.pageObj.tuanzhang = obj.value;
      }
    },

    setPageObjItem(state, obj) {
      if (obj.type == "logo") {
        state.pageObj.logo = obj.value;
      } else if (obj.type == "background") {
        state.pageObj.background = obj.value;
      }
    },
    setHeadIcon(state, obj) {
      state.iconObj.banner[obj.index][obj.key] = obj.value;
      state.iconObj.banner.splice();
    },
    toActive(state, types) {
      if (typeof types == "string") {
        state.active = types;
        state.activeBnnerIndex = 0;
      } else {
        state.active = types.type;
        state.activeBnnerIndex = types.index;
      }
    },
    reset(state) {
      Object.assign(state, {
        active: "top",
        activeBnnerIndex: -1,
        pageObj: {},
        iconObj: {
          types: "headIcon",
          banner: [
            {
              title: "分类",
              links: "",
              introduction: "头部菜单左分类",
              show: "1",
              piclink: "send-gift-o"
            },
            {
              title: "购物车",
              links: "",
              introduction: "头部菜单右分类",
              show: "1",
              piclink: "send-gift-o"
            }
          ]
        },
        bannerList: {
          //首页轮播图
          show: "0",
          types: "slides",
          banner: []
        },
        menuList: {
          style: "5",
          show: "0",
          types: "navigation",
          banner: [
            {
              id: "781",
              cate: null,
              sort: "",
              links: "",
              desc: "",
              title: "菜单名",
              piclink: "/assets/img/icon01.3ab45344.png"
            },
            {
              id: "785",
              cate: null,
              desc: "",
              links: "",
              sort: "",
              title: "分类",
              piclink: "/assets/img/icon01.3ab45344.png"
            }
          ]
        },
        seckill: {
          show: "0",
          title: "限时秒杀",
          title_en: "超值特惠",
          types: "seckill",
          banner: []
        },
        presale: {
          show: "0",
          title: "精品预售",
          title_en: "好产品提前订",
          types: "presale",
          banner: []
        },
        collage: {
          show: "0",
          title: "拼团购物",
          title_en: "好产品提前订",
          types: "collage",
          banner: []
        },
        merchant: {
          show: "0",
          title: "商户类别",
          title_en: "好产品提前订",
          types: "merchant",
          banner: []
        },
        course: {
          show: "0",
          title: "内容付费",
          title_en: "好产品提前订",
          types: "course",
          banner: []
        },
        shop: {
          show: "0",
          title: "精选商品",
          title_en: "",
          style: "0",
          types: "shop",
          banner: []
        },
        news: {
          show: "0",
          title: "实时资讯",
          title_en: "",
          style: "0",
          types: "news",
          text: "",
          banner: []
        },
        partListCon: [],
        footer: {
          show: "0",
          title: "",
          title_en: "",
          style: "0",
          types: "footer",
          text: "",
          banner: [
            { piclink: "home-o", links: "", title: "首页", id: 0, sort: "" }
          ]
        },
        delBanner: "",
        delMudeules: "",
        modules: [],
        showModuleRight: {
          types: "",
          style: "0",
          title: "",
          link: "",
          text: "",
          sort: "",
          show: "1",
          banner: []
        },
        activeModuleIndex: -1
      });
    }
  },
  actions: {}
};

export default pageIndex;
